<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="僵尸商家 待发掘商家" prop="sellerDevelopmentId">
									<el-input v-model="form.sellerDevelopmentId" placeholder="请输入僵尸商家 待发掘商家" clearable></el-input>
								</el-form-item>
								<el-form-item label="分店" prop="departmentId">
									<el-input v-model="form.departmentId" placeholder="请输入分店" clearable></el-input>
								</el-form-item>
								<el-form-item label="跟踪业务员id" prop="sysUserId">
									<el-input v-model="form.sysUserId" placeholder="请输入跟踪业务员id" clearable></el-input>
								</el-form-item>
								<el-form-item label="商家id 待入驻=0" prop="sellerId">
									<el-input v-model="form.sellerId" placeholder="请输入商家id 待入驻=0" clearable></el-input>
								</el-form-item>
								<el-form-item label="名称" prop="name">
									<el-input v-model="form.name" placeholder="请输入名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="主营栏目" prop="categoryPath">
									<el-input v-model="form.categoryPath" placeholder="请输入主营栏目" clearable></el-input>
								</el-form-item>
								<el-form-item label="区域全路径" prop="regionPath">
									<el-input v-model="form.regionPath" placeholder="请输入区域全路径" clearable></el-input>
								</el-form-item>
								<el-form-item label="简述" prop="shortDesc">
									<el-input v-model="form.shortDesc" placeholder="请输入简述" clearable></el-input>
								</el-form-item>
								<el-form-item label="logo" prop="logo">
									<el-input v-model="form.logo" placeholder="请输入logo" clearable></el-input>
								</el-form-item>
								<el-form-item label="地址" prop="address">
									<el-input v-model="form.address" placeholder="请输入地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="电话" prop="phone">
									<el-input v-model="form.phone" placeholder="请输入电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="经度" prop="longitude">
									<el-input v-model="form.longitude" placeholder="请输入经度" clearable></el-input>
								</el-form-item>
								<el-form-item label="纬度" prop="latitude">
									<el-input v-model="form.latitude" placeholder="请输入纬度" clearable></el-input>
								</el-form-item>
								<el-form-item label="录入时间" prop="createTime">
									<el-input v-model="form.createTime" placeholder="请输入录入时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="录入人" prop="createId">
									<el-input v-model="form.createId" placeholder="请输入录入人" clearable></el-input>
								</el-form-item>
								<el-form-item label="1入驻跟进  2付费跟进  3日常维护" prop="type">
									<el-input v-model="form.type" placeholder="请输入1入驻跟进  2付费跟进  3日常维护" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import sellerAPI from '@/api/seller/sellerDevelopment';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '商家拓展'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					sellerDevelopmentId: "",
					departmentId: "",
					sysUserId: "",
					sellerId: "",
					name: "",
					categoryPath: "",
					regionPath: "",
					shortDesc: "",
					logo: "",
					address: "",
					phone: "",
					longitude: "",
					latitude: "",
					createTime: "",
					createId: "",
					type: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await sellerAPI.sellerDevelopment.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.sellerDevelopmentId = data.sellerDevelopmentId;
				this.form.departmentId = data.departmentId;
				this.form.sysUserId = data.sysUserId;
				this.form.sellerId = data.sellerId;
				this.form.name = data.name;
				this.form.categoryPath = data.categoryPath;
				this.form.regionPath = data.regionPath;
				this.form.shortDesc = data.shortDesc;
				this.form.logo = data.logo;
				this.form.address = data.address;
				this.form.phone = data.phone;
				this.form.longitude = data.longitude;
				this.form.latitude = data.latitude;
				this.form.createTime = data.createTime;
				this.form.createId = data.createId;
				this.form.type = data.type;
			}
		}
	}
</script>
<style>
</style>
